package it.storm.solution;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1877. 数组中最大数对和的最小值
 * https://leetcode-cn.com/problems/minimize-maximum-pair-sum-in-array/
 */
public class Solutions_1877 {
    public static void main(String[] args) {
        int[] nums1 = {3, 5, 2, 3};  // output: 7
        int[] nums2 = {3, 5, 4, 2, 4, 6};  // output: 8

        List<int[]> inputs = new ArrayList<>();
        inputs.add(nums1);
        inputs.add(nums2);

        for (int[] input : inputs) {
            int result = minPairSum(input);
            System.out.println(result);
        }
    }

    public static int minPairSum(int[] nums) {
        Arrays.sort(nums);
        int res = 0;
        int len = nums.length;
        for (int i = 0; i < len / 2; i++) {
            res = Math.max(res, nums[i] + nums[len - 1 - i]);
        }
        return res;
    }
}
